package org.bronycorps.mlptss;

import org.bronycorps.mlptss.domain.controller.GameController;
import org.bronycorps.mlptss.manager.CommonAssetManager;
import org.bronycorps.mlptss.manager.ScreenLoader;
import org.bronycorps.mlptss.manager.preferences.GameConfiguration;
import org.bronycorps.mlptss.manager.scripting.ScriptManager;
import org.bronycorps.mlptss.screen.MenuScreen;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.FPSLogger;

public class MlpTss extends Game {

	public final static String LOG = "MLP-TSS";

	private CommonAssetManager assetManager;

	// private int counter = 0;

	private GameConfiguration config;
	private FPSLogger fpsLogger;

	protected String modName;

	public MlpTss() {
		super();
		this.modName = "mlp";
	}

	public MlpTss(String modName) {
		super();
		this.modName = modName;
	}

	// private Runtime runtime;

	public void create() {
		this.fpsLogger = new FPSLogger();

		this.config = GameConfiguration.getInstance();
		this.config.loadFile(this.modName);

		this.assetManager = CommonAssetManager.getInstance();

		ScriptManager.getInstance().loadScripts(this.config);

		ScreenLoader.getInstance().setGame(this);
	}

	@Override
	public void render() {
		super.render();

		this.fpsLogger.log();
	}

	public void resize(int width, int height) {
		super.resize(width, height);

		if (getScreen() == null) {
			this.assetManager.finishLoading();

			GameController gc = GameController.getInstance();

			ScreenLoader.getInstance().loadScreen(new MenuScreen());
		}
	}

}
